<?php
/**
*Smarty plugin
*@Liu Zhongjie
*@Beijing Arouter Co.Ltd
*@2007-2-9
**/

/**
* Smarty {html_div} function plugin
*
* Type:    function<br>
* Name:    html_div<br>
* Date:    Feb 9,2007<br>
* Input:<br>
*         -id        = DIV's id.It's the number for CSS to control its style.(array).!important!
*         -ul        = Unordered Lists.(boolean:true or false ,default false).
*         -ol        = Ordered Lists.(boolean:true or false ,default false).
*         -li        = Unordered Lists & Ordered Lists tag.(inteqer:1 to N(N>=1).
*         -dl        = Definition Lists.(boolean:ture or false ,default false).
*         -dt        = Definition Lists tag.Explained object.(inteqer).
*         -dd        = Definition Lists tag.Content of explanation.(inteqer).
*
* Examples:
* <pre>
* {html_div id='div'}
* {html_div id='div1' ul=1 li=4 content_li=$content}
* {html_div id='div2' ol=1 li=6 content_li=$content}
* {html_div id='div3' dl=1 dt=2 content_dt=$content1 content_dd=$content2}
* </pre>
* @param array
* @param Smarty
* @return string
**/

function smarty_function_html_div ($params, &$smarty)
{
	require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
	
	$id         = NULL;
	$ul         = false;
	$ol         = false;
	$li         = NULL;
    $content_ol = NULL;
    $content_ul = NULL;
	$dl         = false;
	$dt         = NULL;
	$dd         = NULL;
    $content_dt = NULL;
    $content_dd = NULL;

    foreach ($params as $_key=>$_value) {
        switch ($_key) {
            case 'id':
                $$_key = (string)$_value;
                break;

            case 'ul':
            case 'ol':
            case 'dl':
                $$_key = (bool)$_value;
                break;

            case 'li':
            case 'dt':
                $$_key = (int)$_value;
                break;

            case 'content_ul':
            case 'content_ol':
            case 'content_dt':
            case 'content_dd':
                $$_key = (array)$_value;
                break;
        }
    }
    
    if(!isset($id)) return '';
    
    $output  = '<div id="' . smarty_function_escape_special_chars($id) .'"> ';
    $output .= "\n";


    if($ol)
    {
    	$output .= "<ol>\n";
   		for($i=0;$i <= $li-1;$i++){
    		$output .= "<li> $content_ol[$i] </li>\n";
    	}
        $output .= "</ol>\n";
    }
    	
     if($ul)
    {
    	$output .= "<ul>\n";
    	for($m=0;$m <= $li-1;$m++){
    		$output .= "<li> $content_ul[$m] </li>\n";
    	}
        $output .= "</ul>\n";
    }   

     if($dl)
     {
     	$output .= "<dl>\n";
     	for($n=0;$n <= $dt-1;$n++){
     		$output .= "<dt> $content_dt[$n] </dt>\n";
     		$output .= "<dd> $content_dd[$n] </dd>\n";
     	}
     	$output .= "</dl>\n";
     }   

    $output .= "</div>\n";

    return $output;
}
?>